//
//  hongBaoCell.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/6/4.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "hongBaoCell.h"

@implementation hongBaoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(hongBaoModel *)model {
    _model = model;
    self.money_lab.text = [NSString stringWithFormat:@"%.2f", _model.money.doubleValue];
    self.time_lab.text = _model.endTimeStr;
    if (![_model.status isEqualToString:@"0"]) {
        self.backImgV.image = [UIImage imageNamed:@"quanGray"];
        [self.use_btn setTitle:@"已使用" forState:0];
        self.use_btn.enabled = NO;
        [self setGradientWithView:self.use_btn];
    }else {
        self.backImgV.image = [UIImage imageNamed:@"quanRed"];
        [self.use_btn setTitle:@"立即使用>>" forState:0];
        self.use_btn.enabled = YES;
        [self setGradientWithView:self.use_btn];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)useClick:(id)sender {
    
}
- (void)setGradientWithView:(UIButton *)view {
    if (gradientLayer == nil) {
        gradientLayer = [CAGradientLayer layer];
        gradientLayer.startPoint = CGPointMake(0.5, 0);
        gradientLayer.endPoint = CGPointMake(0.5, 1.0);
        gradientLayer.frame = view.bounds;
        //设置颜色分割点（范围：0-1）
        gradientLayer.locations = @[@(0.5f), @(1.0f)];
        [self.back_V.layer insertSublayer:gradientLayer below:view.layer];
    }
    if ([view.titleLabel.text isEqualToString:@"已使用"]) {
         gradientLayer.colors = @[(__bridge id)[UIColor custom_color:@"#FFFFFF"].CGColor, (__bridge id)[UIColor custom_color:@"#C3C2C2"].CGColor];
    }else {
         gradientLayer.colors = @[(__bridge id)[UIColor custom_color:@"#F9E056"].CGColor, (__bridge id)[UIColor custom_color:@"#F2BC42"].CGColor];
    }
}
@end
